﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
    <head>
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
        <meta content="history" name="save">
        <title>SA1213: EventAccessorsMustFollowOrder</title>
        <link rel="stylesheet" type="text/css" href="stylesheets/helpstudio.css"><link rel="stylesheet" type="text/css" href="styles/Presentation.css">
        <script src="script/helpstudio.js" type="text/javascript"></script>
        <script src="script/StandardText.js" type="text/jscript"></script>
    </head>
    <body id="hsbody">
        <input type="hidden" id="userDataCache" class="userDataStyle" name="userDataCache" />
        <div id="allHistory" class="saveHistory" onsave="saveScrollPosition()" onload="loadScrollPosition()"></div>
        <script type="text/jscript">WritePageTop(document.title);</script>
        <div id="pagebody">
            <div id="mainbody">
                <table>
                    <col />
                    <tr><td><p>TypeName</p></td><td><p>EventAccessorsMustFollowOrder</p></td></tr>
                    <tr><td><p>CheckId</p></td><td><p>SA1213</p></td></tr>
                    <tr><td><p>Category</p></td><td><p>Ordering Rules</p></td></tr>
                </table>           
                <h2>Cause</h2>
                <P>An add accessor appears after a remove accessor within an event.</P>
                <H2>Rule Description</H2>
                <P>A violation of this rule occurs when an add accessor is placed after a remove accessor within an event. To comply with this rule, the add accessor should appear before the remove accessor.</P>
                <P>For example, the following code would raise an instance of this violation:</P>
                <P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-vertical-align-alt: auto; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN>&nbsp;<SPAN style="COLOR: blue">event EventHandler&nbsp;</SPAN>NameChanged</SPAN></P>
                <P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-vertical-align-alt: auto; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{ <o:p></o:p></SPAN></P><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US><SPAN style="mso-spacerun: yes">
                <P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-vertical-align-alt: auto; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">remove</SPAN> { <SPAN style="COLOR: blue">this</SPAN>.nameChanged -= <SPAN style="COLOR: blue">value</SPAN>; }<o:p></o:p></SPAN></P>
                <P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-vertical-align-alt: auto; mso-layout-grid-align: none" class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: blue">add</SPAN> { <SPAN style="COLOR: blue">this</SPAN>.nameChanged += <SPAN style="COLOR: blue">value</SPAN>; }<o:p></o:p></SPAN></P>
                <P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-vertical-align-alt: auto; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
                <P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-vertical-align-alt: auto; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US></SPAN>&nbsp;</P><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US><SPAN lang=EN-US>
                <P>The code below would not raise this violation:</P>
                <p />
                <P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-vertical-align-alt: auto; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN>&nbsp;<SPAN style="COLOR: blue">event EventHandler&nbsp;</SPAN>NameChanged</SPAN></P>
                <P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-vertical-align-alt: auto; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{ </P>
                <P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-vertical-align-alt: auto; mso-layout-grid-align: none" class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: blue">add</SPAN> { <SPAN style="COLOR: blue">this</SPAN>.nameChanged += <SPAN style="COLOR: blue">value</SPAN>; }<o:p></o:p></P><o:p></o:p></SPAN><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US><SPAN style="mso-spacerun: yes">
                <P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-vertical-align-alt: auto; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">remove</SPAN> { <SPAN style="COLOR: blue">this</SPAN>.nameChanged -= <SPAN style="COLOR: blue">value</SPAN>; }<o:p></o:p></SPAN></P></SPAN></SPAN>
                <P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-vertical-align-alt: auto; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></P>
                <P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-vertical-align-alt: auto; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes" lang=EN-US></SPAN>&nbsp;</P></SPAN></SPAN></SPAN>
                <H2>How to Fix Violations</H2>
                <P>To fix an instance of this violation, place the add accessor before the remove accessor.</P>
                <h2>How to Suppress Violations</h2>
                <pre>[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1213:EventAccessorsMustFollowOrder", Justification = "Reviewed.")]</pre>
            </div>
            <script type="text/jscript">WritePageFooter();</script>     
        </div>
    </body>
</html>